package org.alps.demo.logstack.aspect;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * AOP切面统一打印请求日志
 * @date 2021-05-31
 * @author zkw
 */
@Aspect
@Component
@Slf4j
@SuppressWarnings("all")
public class WebLogAspect {
    @Autowired
    private ObjectMapper mapper;
    private static final Integer PRINT_LOG_SIZE_LIMIT = 100;

    @Pointcut("execution(public * org.alps.demo.logstack.controller..*.*(..)))")
    public void webLog() { }

    @Before("webLog()")
    public void doBefore(Joinpoint joinpoint) throws Throwable {

    }

    @After("webLog()")
    public void doAfter() throws Throwable {
        log.debug("================== Request Done ==================");
        log.debug("");
    }

    @Around("webLog()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //StopWatch sw = StopWatch.createStarted();

        return "";
    }
}
